package com.gymjournal

class Training {
    static hasMany = [gymnastics: Gymnastic]

    Note note
    List<Gymnastic> gymnastics

    Date dateCreated    //todo think about date of training
    Date startDate
    Date finishDate

    static constraints = {
        note(nullable: true)
        gymnastics(nullable: true)
        dateCreated(nullable: true)
        startDate(nullable: true)
        finishDate(nullable: true, validator: {finishDate, training ->
            training.startDate != null && training.finishDate != null ||
                    training.startDate == null && training.finishDate == null
        })

    }

    @Override
    String toString() {
        startDate != null ? startDate : dateCreated
    }
}
